﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class PaylerController : MonoBehaviour {
    public float speed;
    public Text countText;
    public Text winText;
    //
    private Rigidbody rb;
    private int count;
    // Use this for initialization
    void Start()
    {
        rb = GetComponent<Rigidbody>();//Get context's Rigiedbody.
        speed = 12;
        count = 0;
        winText.text = "";
        SetCountText();
    }

    // Update is called once per frame
    void Update()
    {

    }
    void FixedUpdate()
    {
        var moveHorizontal = Input.GetAxis("Horizontal");
        var moveVertical = Input.GetAxis("Vertical");
        Vector3 movement = new Vector3(moveHorizontal, 0, moveVertical);
        rb.AddForce(movement * speed);
    }
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("PickUp"))
        {
            other.gameObject.SetActive(false);
            Destroy(other.gameObject);
            count = count + 1;
            SetCountText();
        }
        
    }
    void SetCountText()
    {
        countText.text = "Count:" + count;
        if (count>=12)
        {
            winText.text = "You Win!";
        }
    }
}
